<template>
    <ma-form-modal ref="addMoneyRef" :columns="columns" title="退款" :submit="submit" v-if='type'>
  
    </ma-form-modal>
  </template>
  
  <script setup>
  import MaFormModal from "@/components/ma-form-modal/index.vue"
  import {ref} from "vue";
  import dept from "@/api/system/dept";
  import financialMoneyApply from '@/api/financial/financialMoneyApply'
  import {Message} from "@arco-design/web-vue";
  const type = ref()
  const modalShow = ref(false)
  const money = ref('')
  const columns = ref([
    {
      title: "客户公司",
      dataIndex: "dept_id",
      formType: "select",
      disabled:true,
      dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: "system/dept/remote",
        // 指定组件接收的props
        props: { label: "name", value: "id" },
        // 开启分页
        openPage: false,
        // 远程请求配置项
        remoteOption: {
          // 按用户名排序
          sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
          // 设置查询的字段
          select: ["id", "name"],
          // 设置数据过滤
          filter: {
            type: ["=", 2],
            status: ['=',1]
          },
          // 关联模型
          relations: [],
        },
      },
      rules: {
        required: true,
        message: "请选择提现公司"
      }
    },
    {
      title: "退款金额",
      dataIndex: "money",
      formType: "input",
      search: true,
      min: 0,
      rules: {
        required: true,
        message: "请输入退款金额"
      }
    },
    // {
    //   title: "上传凭证",
    //   dataIndex: "files",
    //   formType: "upload",
    //   type: "image",
    //   returnType: "url",
    //   multiple: true,
    //   onlyUrl: true,
    //   rules: {
    //     required: true,
    //     message: "请上传支付凭证"
    //   }
    // },
    {
      title: "备注",
      dataIndex: "remark",
      formType:"textarea"
    }
  ])
  const addMoneyRef = ref()
  
  const submit = async (data) => {
    console.log('8/8888888888')
    if((money.value - 0) < (data.money - 0)){
      return Message.error('余额不足')
    }
    console.log('999999999:',data)
   
    let res = await financialMoneyApply.save({
      ...data,
    })
    if (res.success) {
      Message.success(res.message)
      callbackFunction(res)
      return true
    }
    return false
  }
  var callbackFunction = null
  defineExpose({
    open(data, callback){
      this.callback(callback)
      modalShow.value = true
      type.value = data.type
      money.value = data.money
      setTimeout(() => {
        if(data.type == 1){
          addMoneyRef.value.open({type:2 })
        }else{
          addMoneyRef.value.open({type:2,dept_id:data.dept_id })
        }
      }, 50);
      
    },
    callback(callback){
      callbackFunction = callback
    }
  })
  </script>
  
  <style scoped>
  
  </style>
  